package Others;

import java.util.ArrayList;
import java.util.List;

public class _796_RotateString {
    //reference solution:combine A and A and check if B is a substring of a
    public boolean rotateString_0(String A, String B) {
        return (A.length() == B.length()) && (A + A).contains(B);
    }

    //solution 2:compare
    public boolean rotateString(String A, String B) {
        int Alength = A.length();
        int Blength = B.length();
        if(Alength!=Blength) return false;
        if(Alength ==0 && Blength ==0) return true;
        List<Integer> positions = new ArrayList<>();
        for (int i = 0; i < Blength; i++) {
            if (B.charAt(i) == A.charAt(0)) {
                positions.add(i);
            }
        }
        for (int i : positions) {
            String temp = B.substring(i, Blength) + B.substring(0, i);
//            System.out.println(temp);
            if (temp.equals(A)) {
                return true;
            }
        }
        return false;
    }
}
